import { defHttp } from '/@/utils/http/axios';
import { ApiCommon } from '../common';
const { SYS_ADMIN_API } = ApiCommon;
const AUTH_USER_API = SYS_ADMIN_API + '/auth';
const CAPTCHA_API = SYS_ADMIN_API + '/captcha';
// /v1.0/sys/admin/auth
enum Api {
  IMAGE_CODE = '/get-image', // 获取图片验证码
  LOGIN = '/login', //分页查询客户
  USER_INFO = '/get-permission-info', // 用户权限信息
  LOGOUT = '/logout', // 退出登录
  QUERY_USER = '/query-by-phone', // 根据手机号或者用户名查询用户
  SMS_CODE = '/send-sms-code', // 发送短信验证码
  EIDT_PASSWORD = '/change-password', // 修改密码
  DEPT_GET = '/dept/get-dept',
  CHANGE_PASSWORD = '/auth/password-change-password',
}
/**
 * @description: 请求的API地址
 */
export const captchaApi = () => defHttp.get({ url: CAPTCHA_API + Api.IMAGE_CODE }); //图片验证码
export const loginApi = (data: object) => defHttp.post({ url: AUTH_USER_API + Api.LOGIN, data }); //账号密码登录
export const getUserInfo = () => defHttp.get({ url: AUTH_USER_API + Api.USER_INFO }); //账号密码登录
export const logout = () => defHttp.post({ url: AUTH_USER_API + Api.LOGOUT }); // 用户退出登录
export const queryUser = (params: object) =>
  defHttp.get({ url: AUTH_USER_API + Api.QUERY_USER, params }); // 根据手机号或者用户名查询用户
export const sendCodeApi = (data: object) =>
  defHttp.post({ url: AUTH_USER_API + Api.SMS_CODE, data }); // 发送短信验证码
export const updatePasswordApi = (data: object) =>
  defHttp.post({ url: AUTH_USER_API + Api.EIDT_PASSWORD, data }); // 发送短信验证码
export const deptGetApi = async () => {
  const res = await defHttp.get({ url: SYS_ADMIN_API + Api.DEPT_GET });
  if (res.code === 0) {
    return res.data;
  }
  return [];
}; //当前账号的部门

// 修改密码
export const changePassword = (params: object) =>
  defHttp.post({ url: SYS_ADMIN_API + Api.CHANGE_PASSWORD, params });
